package com.hlhj.carview.aty

import android.content.Intent
import android.net.Uri
import com.hlhj.carview.BaseAty
import com.hlhj.carview.Iview.NothingView
import com.hlhj.carview.R
import com.hlhj.carview.adapter.MuPagerAdp
import com.hlhj.carview.bean.GIverDetailBean
import com.hlhj.carview.customView.MyPagerTransformer
import com.hlhj.carview.http.CustomAction
import com.hlhj.carview.http.MyJsonConvert
import com.hlhj.carview.http.Urls
import com.hlhj.carview.presenter.NothingPresenter
import com.lzy.okgo.OkGo
import com.lzy.okgo.model.HttpParams
import com.lzy.okgo.model.Response
import com.lzy.okrx2.adapter.ObservableResponse
import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.giver_detail_aty.*
import kotlinx.android.synthetic.main.lo_pubhead.*

/**
 *NeverMore
 *2020/9/16
 **/
class GiverDetailAty:BaseAty<NothingView,NothingPresenter>(), NothingView {
    private var adp:MuPagerAdp?=null

    override fun initView() {

        tvTittle.text="${intent.getStringExtra("title")}"
    }

    override fun logicStart() {
        val httpParams = HttpParams()
        httpParams.put("uriPath","giverDetail")
        httpParams.put("aid",intent.getStringExtra("aid"))
        OkGo.post<GIverDetailBean>(Urls.PubUrl)
                .headers("type",3.toString())
                .params(httpParams)
                .converter(object : MyJsonConvert<GIverDetailBean>(){})
                .adapt(ObservableResponse<GIverDetailBean>())
                .subscribeOn(Schedulers.io())
                .subscribe(object : CustomAction<Response<GIverDetailBean>>(this){
                    override fun httpSuccess(t: Response<GIverDetailBean>) {
                        val arrayList = ArrayList<String>()
                        val get = t.body().data?.get(0)
                       val s= get?.imgs?.split(",")
                        s?.forEach {
                            arrayList.add(it)
                        }
                        adp=MuPagerAdp(arrayList,this@GiverDetailAty)
                        newBanner.adapter=adp
                        newBanner.setPageTransformer(false,MyPagerTransformer())

                        phoneNum.text="招贤热线:${get?.phone}"
                        btPhone?.setOnClickListener {
                            // Intent : 意图.我想去做一件事
                            val t = Intent()
                            // Action:动作.我具体想做什么事
                            // Intent.ACTION_DIAL: 激活拨号界面
                            // Intent.ACTION_CALL: 直接拨打电话
                            t.action = Intent.ACTION_CALL
                            // Data: 数据.具体的动作所需要的附加数据
                            //封装一个拨打电话的intent，并且将电话号码包装成一个Uri对象传入
                            t.data = Uri.parse("tel:" + get?.phone)
                            // 通知系统你去帮我干活吧
                            startActivity(t)
                        }
                        tvDes.text="${intent.getStringExtra("des")}"
                    }
                })
    }

    override fun setListener() {

    }

    override fun getContentID(): Int {
        return R.layout.giver_detail_aty
    }

    override fun bindView(): NothingView {
        return this
    }

    override fun createPresenter(): NothingPresenter {
        return NothingPresenter()
    }
}